home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / MorphOS / Source / LUP2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-10  |  2.0 KB  |  106 lines

  1. #include    <clib/all_protos.h>
  2. #include    <exec/types.h>
  3. #include    <math.h>
  4. #include    <float.h>
  5.  
  6. extern void PlotIt(UWORD);
  7. extern double Limit,XCenter,Factor,Two,PowerN,Pi,PiD2,TwoPi,DX;
  8. extern double PowerF;
  9. extern SHORT Power;
  10. extern UWORD Color;
  11. extern LONG xtemp,MaxCnt,RightEdge;
  12. extern ULONG *ColorTable32,*LPixelBuf;
  13. extern int BPP;
  14.  
  15. double ReduceTheta(double);
  16.  
  17. double GetTheta(double,double);
  18.  
  19. double GetTheta(double xVal,double yVal)
  20. {
  21. double    Ratio,Theta;
  22.     Ratio  = yVal/xVal;
  23.     if (Ratio*Ratio <= 1.0e4) {
  24.         Theta = atan(Ratio);
  25.         if (xVal < 0.) Theta = Theta + Pi;
  26.         if (Theta < 0.) Theta = Theta + TwoPi;
  27.         return(Theta);
  28.         }
  29.     else {
  30.         Theta = PiD2 - atan2(xVal,yVal);
  31.         if (Theta < 0.) Theta = Theta + TwoPi;
  32.         return(Theta);
  33.         }
  34. }
  35.  
  36. double ReduceTheta(double Theta)
  37. {
  38.     while (Theta > TwoPi) Theta = Theta - TwoPi;
  39.     return(Theta);
  40. }
  41.  
  42. /* Note that GetRadN is faster than using PowerN*log(Zr)    */
  43. double GetRadN(double Zr)
  44. {
  45. double RadN,RadM;
  46. int Cnt;
  47.     RadM = Zr;
  48.     for (Cnt=1;Cnt<Power;Cnt++) RadM = RadM*Zr;
  49.     RadN = PowerF*log(Zr);
  50.     RadN = exp(RadN);
  51.     RadN = RadM*RadN;
  52.     return(RadN);
  53. }
  54.  
  55. void FncFnd(double yRelL)
  56. {
  57. double    xRel,yRel,Rad2,Rad,Theta,ThetaN,RadN,Rad2N,Zr,Za,Zr2;
  58. ULONG *ColSrc;
  59. int CurCnt;
  60.     yRel = yRelL;
  61.     xtemp = 0;
  62.     while (xtemp < RightEdge)    {
  63.         xRel = (double)xtemp - XCenter;
  64.         xRel = xRel/Factor;
  65.  
  66.         yRelL = yRel;
  67.         Rad2 = xRel*xRel + yRelL*yRelL;
  68.         Theta = GetTheta(xRel,yRelL);
  69.         Rad = sqrt(Rad2);
  70.  
  71.         CurCnt = 1;
  72.         Zr = Rad;
  73.         Za = Theta;
  74.         Zr2 = Zr*Zr;
  75.         while (CurCnt < MaxCnt)    {
  76.             if (Zr2 > Limit)    {
  77.                 Color = CurCnt;
  78.                 goto Finish;
  79.                 }
  80.                 if (Zr)    {
  81.                     RadN = GetRadN(Zr);
  82.                     Rad2N = RadN*RadN;
  83.                     }
  84.                 else     {
  85.                     Color = 0xffff;
  86.                     goto Finish;
  87.                     }
  88.                 ThetaN = PowerN*Za - Theta;
  89.                 Zr2 = Rad2 + Rad2N + Two*Rad*RadN*cos(ThetaN);
  90.                 Zr = sqrt(Zr2);
  91.                 yRelL = RadN*sin(ThetaN);
  92.                 xRel = Rad + RadN*cos(ThetaN);
  93.                 Za = Theta + GetTheta(xRel,yRelL);
  94.                 CurCnt++;
  95.                 }
  96.     Color = 0xffff;
  97. Finish:
  98.     if (BPP < 2) PlotIt(Color);
  99.     else    {
  100.         ColSrc = (ULONG *)ColorTable32 + (ULONG)Color;
  101.         *LPixelBuf++ = *ColSrc;
  102.         }
  103.     xtemp++;
  104.     }
  105. }
  106.